package com.group.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.group.config.Async;
import com.group.entity.ProjectOutside;
import com.group.entity.User;
import com.group.mapper.ProjectOutsideMapper;
import com.group.mapper.UserMapper;
import com.group.service.ProjectOutsideService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;

@Controller
@SuppressWarnings("all")
public class ManageMentController {
    @Autowired
    UserMapper userMapper;
    @Autowired
    Async async;
    @Autowired
    ProjectOutsideMapper projectOutsideMapper;
    @Autowired
    ProjectOutsideService projectOutsideService;


    //返回敏感词的项目
    @RequestMapping("/findMinGan")
    public List<ProjectOutside> findMinGan() {
        List<ProjectOutside> minGanProjectlist = async.findMinGanProject();
        return minGanProjectlist;
    }

    //通过projectId 来封禁项目，前端需要传projectId
    @GetMapping("/banProjectId/{projectId}")
    public void banProjectId(@PathVariable("projectId") Integer projectId) {
        //逻辑删除,status == 1 表示逻辑删除，除了后台都查不到，查询不到，无法登陆
        projectOutsideMapper.deleteById(projectId);
    }

    //封禁用户接口
    @RequestMapping("/banId/{id}")
    public void banId(@PathVariable("id") Integer id) {
        //逻辑删除，查询不到，无法登陆
        userMapper.deleteById(id);
    }

    //用户修改密码接口
    @RequestMapping("/updatePassWord/{userName}")
    public String updatePassWord(@PathVariable("userName") String userName) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("userName", userName);
        User user = userMapper.selectOne(wrapper);
        user.setPassWord("123456");
        userMapper.updateById(user);
        return null;
    }
}
